/* Copyright 2023 The MediaPipe Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Defines topology of the GHUM model. This is related only to the 3D model of the
body, not the way NN models predict joint rotations for it.
==============================================================================*/

#ifndef MEDIAPIPE_TASKS_CC_VISION_UTILS_GHUM_GHUM_TOPOLOGY_H_
#define MEDIAPIPE_TASKS_CC_VISION_UTILS_GHUM_GHUM_TOPOLOGY_H_

#include <array>

namespace mediapipe::tasks::vision::utils::ghum {

// GHUM 63 joint names in order they are produced by the PoseRig and
// XenomorphRig pipelines.
//
// Note that some joints will always remain in default rotation (i.e.
// kGhumDefaultJointRotation) depending on what joints are supported by the
// pipeline.
enum class GhumJointName {
  kPelvis = 0,
  kSpine01,
  kSpine02,
  kSpine03,
  kNeck01,
  kHead01,
  kJaw01,
  kEye01L,
  kEyelidup01L,
  kEye01R,
  kEyelidup01R,
  kEyeliddown01L,
  kEyeliddown01R,
  kClavicleL,
  kUpperarmL,
  kLowerarmL,
  kHandL,
  kIndex01L,
  kIndex02L,
  kIndex03L,
  kMiddle01L,
  kMiddle02L,
  kMiddle03L,
  kRing01L,
  kRing02L,
  kRing03L,
  kPinky01L,
  kPinky02L,
  kPinky03L,
  kThumb01L,
  kThumb02L,
  kThumb03L,
  kClavicleR,
  kUpperarmR,
  kLowerarmR,
  kHandR,
  kIndex01R,
  kIndex02R,
  kIndex03R,
  kMiddle01R,
  kMiddle02R,
  kMiddle03R,
  kRing01R,
  kRing02R,
  kRing03R,
  kPinky01R,
  kPinky02R,
  kPinky03R,
  kThumb01R,
  kThumb02R,
  kThumb03R,
  kThighL,
  kCalfL,
  kAnkleL,
  kFootL,
  kBallL,
  kToes01L,
  kThighR,
  kCalfR,
  kAnkleR,
  kFootR,
  kBallR,
  kToes01R,
};

// GHUM default joint rotation. When applied - won't change initial pose of 3D
// model.
constexpr std::array<int, 6> kGhumDefaultJointRotation = {{1, 0, 0, 1, 0, 0}};

// GHUM resting joint positions defined in 6D rotation format. Joint rotations
// produced by Hund models should be applied ON TOP OF THEM (i.e. multiplied).
//
constexpr std::array<std::array<float, 6>, 63> kGhumRestingJointRotations = {{
    {3.3306690738754696e-16, -1.1102230246251565e-16, 0.9907665252685547,
     0.1355789452791214, -0.1355789452791214, 0.9907665252685547},
    {-2.220446049250313e-16, -2.220446049250313e-16, 0.9965463876724243,
     -0.08303803205490112, 0.08303803205490112, 0.9965463876724243},
    {2.220446049250313e-16, -1.1102230246251565e-16, 0.9830689430236816,
     0.1832359880208969, -0.1832359880208969, 0.9830689430236816},
    {0.0, -1.1102230246251565e-16, 0.9998827576637268, -0.015312896110117435,
     0.015312896110117435, 0.9998827576637268},
    {1.1102230246251565e-16, -1.1102230246251565e-16, 0.9737479090690613,
     -0.22762899100780487, 0.22762899100780487, 0.9737479090690613},
    {0.0, -2.220446049250313e-16, 0.9975937008857727, -0.06933078169822693,
     0.06933078169822693, 0.9975937008857727},
    {0.0, 0.0, -0.7646467089653015, 0.6444497108459473, 0.6444497108459473,
     0.7646467089653015},
    {1.0, 0.0, 0.0, 1.0, 0.0, 0.0},
    {1.0, 0.0, 0.0, 1.0, 0.0, 0.0},
    {1.0, 0.0, 0.0, -1.0, 0.0, -1.2246468525851679e-16},
    {1.0, 0.0, 0.0, -1.0, 0.0, -1.2246468525851679e-16},
    {1.0, 0.0, 0.0, 1.0, 0.0, 0.0},
    {1.0, 0.0, 0.0, -1.0, 0.0, -1.2246468525851679e-16},
    {0.8921475410461426, 0.2971198558807373, -0.17762203514575958,
     0.9233117699623108, -0.41535913944244385, 0.24334177374839783},
    {0.4769144654273987, 0.87869793176651, -0.878876805305481,
     0.4764299690723419, -0.011322125792503357, 0.03007427789270878},
    {0.5015625953674316, 0.865040123462677, -0.8650957345962524,
     0.5016061067581177, 0.00665692426264286, 0.009843245148658752},
    {0.5015625953674316, 0.865040123462677, -0.8650957345962524,
     0.5016061067581177, 0.00665692426264286, 0.009843245148658752},
    {0.37746769189834595, 0.8884291648864746, -0.9007542133331299,
     0.4176981747150421, 0.21484869718551636, 0.1903204619884491},
    {0.37291213870048523, 0.9067361354827881, -0.9177148342132568,
     0.39173614978790283, 0.13687947392463684, 0.1561165302991867},
    {0.37291213870048523, 0.9067361354827881, -0.9177148342132568,
     0.39173614978790283, 0.13687947392463684, 0.1561165302991867},
    {0.46410179138183594, 0.8850933313369751, -0.8857383131980896,
     0.4641091823577881, -0.008784775622189045, -0.03482021763920784},
    {0.4025099277496338, 0.9154127836227417, -0.9146613478660583,
     0.4022779166698456, 0.03715258091688156, -0.013853170908987522},
    {0.4025099277496338, 0.9154127836227417, -0.9146613478660583,
     0.4022779166698456, 0.03715258091688156, -0.013853170908987522},
    {0.34835490584373474, 0.8863212466239929, -0.9299189448356628,
     0.36770808696746826, -0.11789664626121521, -0.28147009015083313},
    {0.35047438740730286, 0.8873153328895569, -0.9331605434417725,
     0.35812410712242126, -0.07986952364444733, -0.2905488610267639},
    {0.35047438740730286, 0.8873153328895569, -0.9331605434417725,
     0.35812410712242126, -0.07986952364444733, -0.2905488610267639},
    {0.29830706119537354, 0.7789736986160278, -0.9084595441818237,
     0.4089738428592682, -0.2927698493003845, -0.4753318727016449},
    {0.2655753493309021, 0.7524029612541199, -0.9429818987846375,
     0.33284398913383484, -0.2006361186504364, -0.5684230327606201},
    {0.2655753493309021, 0.7524029612541199, -0.9429818987846375,
     0.33284398913383484, -0.2006361186504364, -0.5684230327606201},
    {-0.1977168470621109, -0.2275119423866272, -0.7548012137413025,
     0.6559536457061768, 0.6254464387893677, 0.719696581363678},
    {-0.07406296581029892, -0.2195579558610916, -0.947542130947113,
     0.3196309804916382, 0.31093189120292664, 0.9217539429664612},
    {-0.07406296581029892, -0.2195579558610916, -0.947542130947113,
     0.3196309804916382, 0.31093189120292664, 0.9217539429664612},
    {0.8921475410461426, 0.2971198558807373, 0.17762203514575958,
     -0.9233117699623108, 0.41535913944244385, -0.24334177374839783},
    {0.4769144654273987, 0.87869793176651, 0.878876805305481,
     -0.4764299690723419, 0.011322125792503357, -0.03007427789270878},
    {0.5015625953674316, 0.865040123462677, 0.8650957345962524,
     -0.5016061067581177, -0.00665692426264286, -0.009843245148658752},
    {0.5015625953674316, 0.865040123462677, 0.8650957345962524,
     -0.5016061067581177, -0.00665692426264286, -0.009843245148658752},
    {0.37746769189834595, 0.8884291648864746, 0.9007542133331299,
     -0.4176981747150421, -0.21484869718551636, -0.1903204619884491},
    {0.37291213870048523, 0.9067361354827881, 0.9177148342132568,
     -0.39173614978790283, -0.13687947392463684, -0.1561165302991867},
    {0.37291213870048523, 0.9067361354827881, 0.9177148342132568,
     -0.39173614978790283, -0.13687947392463684, -0.1561165302991867},
    {0.46410179138183594, 0.8850933313369751, 0.8857383131980896,
     -0.4641091823577881, 0.008784775622189045, 0.03482021763920784},
    {0.4025099277496338, 0.9154127836227417, 0.9146613478660583,
     -0.4022779166698456, -0.03715258091688156, 0.013853170908987522},
    {0.4025099277496338, 0.9154127836227417, 0.9146613478660583,
     -0.4022779166698456, -0.03715258091688156, 0.013853170908987522},
    {0.34835490584373474, 0.8863212466239929, 0.9299189448356628,
     -0.36770808696746826, 0.11789664626121521, 0.28147009015083313},
    {0.35047438740730286, 0.8873153328895569, 0.9331605434417725,
     -0.35812410712242126, 0.07986952364444733, 0.2905488610267639},
    {0.35047438740730286, 0.8873153328895569, 0.9331605434417725,
     -0.35812410712242126, 0.07986952364444733, 0.2905488610267639},
    {0.29830706119537354, 0.7789736986160278, 0.9084595441818237,
     -0.4089738428592682, 0.2927698493003845, 0.4753318727016449},
    {0.2655753493309021, 0.7524029612541199, 0.9429818987846375,
     -0.33284398913383484, 0.2006361186504364, 0.5684230327606201},
    {0.2655753493309021, 0.7524029612541199, 0.9429818987846375,
     -0.33284398913383484, 0.2006361186504364, 0.5684230327606201},
    {-0.1977168470621109, -0.2275119423866272, 0.7548012137413025,
     -0.6559536457061768, -0.6254464387893677, -0.719696581363678},
    {-0.07406296581029892, -0.2195579558610916, 0.947542130947113,
     -0.3196309804916382, -0.31093189120292664, -0.9217539429664612},
    {-0.07406295835971832, -0.2195579558610916, 0.947542130947113,
     -0.3196309804916382, -0.31093189120292664, -0.9217539429664612},
    {-0.01636510342359543, 0.01171059813350439, -0.9988228678703308,
     0.045474592596292496, 0.04566308110952377, 0.9988968372344971},
    {0.05019572749733925, 0.024085810407996178, -0.9970070123672485,
     -0.05764812231063843, -0.05879946053028107, 0.9980463981628418},
    {-0.012483594939112663, -0.038166593760252, -0.9944827556610107,
     0.104560986161232, 0.10415486991405487, 0.9937858581542969},
    {3.3306690738754696e-16, 2.7755575615628914e-17, -0.30688488483428955,
     0.9517466425895691, 0.9517466425895691, 0.30688488483428955},
    {-0.06284070760011673, -0.009795981459319592, -0.15403378009796143,
     0.9880656003952026, 0.9860652089118958, 0.15372197329998016},
    {2.220446049250313e-16, 6.938893903907228e-18, -0.0882575735449791,
     0.9960976839065552, 0.9960976839065552, 0.0882575735449791},
    {-0.01636510342359543, 0.01171059813350439, 0.9988228678703308,
     -0.045474592596292496, -0.04566308110952377, -0.9988968372344971},
    {0.05019572749733925, 0.024085810407996178, 0.9970070123672485,
     0.05764812231063843, 0.05879946053028107, -0.9980463981628418},
    {-0.012483594939112663, -0.038166593760252, 0.9944827556610107,
     -0.104560986161232, -0.10415486991405487, -0.9937858581542969},
    {3.3306690738754696e-16, -8.326672684688674e-17, 0.30688488483428955,
     -0.9517466425895691, -0.9517466425895691, -0.30688488483428955},
    {-0.06284070760011673, -0.009795981459319592, 0.15403378009796143,
     -0.9880656003952026, -0.9860652089118958, -0.15372197329998016},
    {2.220446049250313e-16, -1.1796119636642288e-16, 0.0882575735449791,
     -0.9960976839065552, -0.9960976839065552, -0.0882575735449791},
}};

}  // namespace mediapipe::tasks::vision::utils::ghum

#endif  // MEDIAPIPE_TASKS_CC_VISION_UTILS_GHUM_GHUM_TOPOLOGY_H_
